﻿// Creado por Sergio. 20/06/10.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Engine
{
    /// <summary>
    /// Clase que contiene funcionalidad de la camara en 3ra persona (hereda de Camara)
    /// </summary>
    public class ThirdPersonCamera : Camera
    {
        Vector3 mTarget = Vector3.Zero; // objetivo al que apunta la camara de 3ra persona
        Vector3 mTargetOffset = Vector3.Zero; // distancia a la que esta camara del objetivo

        #region Constructores

        public ThirdPersonCamera(Viewport viewport, Vector3 pos, Vector3 target)
            : base(viewport, pos, target)
        {
            mTarget = target;
            mTargetOffset = mTarget + mTransform.Position;
        }
        public ThirdPersonCamera(Viewport viewport, Vector3 pos, Vector3 target, Vector3 targetOffset)
            : base(viewport, pos, target)
        {
            mTarget = target;
            mTargetOffset = targetOffset;
        }

        #endregion

        public Vector3 TargetOffset
        {
            get { return this.mTargetOffset; }
            set { this.mTargetOffset = value; }
        }

        public void Update(Vector3 target)
        {
            mTarget = target;
            
            mTransform.Position = mTarget + mTargetOffset;

            mTransform.LookAt(mTarget);

            base.Update();
        }

        public void RotateAroundTarget(float angle)
        {
           
            mTransform.RotateAround(mTarget, Vector3.Up, angle);
            mTargetOffset = mTransform.Position - mTarget;
        }

        public void ZoomToTarget(float speed)
        {
            if (Vector3.Distance(mTarget, mTransform.Position) > 0)
                mTargetOffset = mTransform.Position + mTransform.Forward * speed - mTarget;
        }

    }
}
